package leeon.kaixin.wap.models;

import java.io.Serializable;

import leeon.mobile.BBSBrowser.utils.HTMLUtil;

public class Picture implements Serializable {

	public static Picture newInstance(String htmlDiv) {
		if (htmlDiv == null || htmlDiv.length() == 0) return null;
//		<a href="/photo/view.php?verify=12560532_2538938_1301044458_fc314b65923bc7bc8989fe92413b8524_kx&amp;uid=12560532&amp;albumid=34281335&amp;puid=12560532&amp;passwd=&amp;viewtype=0">
//		<img src="http://p.kaixin001.com/privacy/photo/23/31/12560532_596233191_mid.jpg?1a4b7db625665dfcb7e093bf08d01ba5" alt="照片下载中" border="0" /></a>
//		<br/>无标题<br/>
//		<a href="/photo/view.php?verify=12560532_2538938_1301044458_fc314b65923bc7bc8989fe92413b8524_kx&amp;uid=12560532&amp;puid=12560532&amp;pid=596233191&amp;passwd=&amp;viewtype=1">查看中图</a>&nbsp;
//		<a href="/photo/view.php?verify=12560532_2538938_1301044458_fc314b65923bc7bc8989fe92413b8524_kx&amp;uid=12560532&amp;puid=12560532&amp;pid=596233191&amp;passwd=&amp;viewtype=2">查看大图</a><br/> 
//		<a href='/photo/view.php?verify=12560532_2538938_1301044458_fc314b65923bc7bc8989fe92413b8524_kx&amp;uid=12560532&amp;albumid=34281335&amp;puid=12560532&amp;passwd=&amp;viewtype=0'>下一张</a> 
//		<a href='/photo/view.php?verify=12560532_2538938_1301044458_fc314b65923bc7bc8989fe92413b8524_kx&amp;uid=12560532&amp;albumid=34281335&amp;puid=12560532&amp;pid=596233243&amp;passwd=&amp;viewtype=0'>上一张</a>
//		<span class="c9">(7/7)</span>		
		Picture p = new Picture();
		p.url = HTMLUtil.findStr(htmlDiv, "<img src=\"", "\"");
		if (p.url != null && p.url.indexOf("?") != -1) p.url = p.url.substring(0, p.url.indexOf("?"));
		p.albumid = HTMLUtil.findStr(htmlDiv, "albumid=", "&amp");
		p.ourl = HTMLUtil.findStrBeforeTag(htmlDiv, "下载原图", "href=\"", "\"");
		p.nurl = HTMLUtil.findStrBeforeTag(htmlDiv, "下一张", "href='", "'");
		p.purl = HTMLUtil.findStrBeforeTag(htmlDiv, "上一张", "href='", "'");
		if (p.nurl != null) p.nurl = p.nurl.replace("&amp;", "&");
		if (p.purl != null) p.purl = p.purl.replace("&amp;", "&");
		String c = HTMLUtil.findStr(htmlDiv, "<span class=\"c9\">(", ")</span>");
		try {
			p.no = Integer.parseInt(c.substring(0, c.indexOf('/')));
			p.count = Integer.parseInt(c.substring(c.indexOf('/')+1));
		} catch (NumberFormatException e) {
		}
		p.title = HTMLUtil.findStr(htmlDiv, "<br/>", "<br/>");
		return p;
	}
	
	private static final long serialVersionUID = 721141481399562176L;
	
	private String url;
	
	private String ourl;
	
	private String albumid;
	
	private String nurl;
	
	private String purl;
	
	private String title;
	
	private int count;
	
	private int no;

	public int getCount() {
		return count;
	}

	public void setCount(int count) {
		this.count = count;
	}

	public int getNo() {
		return no;
	}

	public void setNo(int no) {
		this.no = no;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getAlbumid() {
		return albumid;
	}

	public void setAlbumid(String albumid) {
		this.albumid = albumid;
	}

	public String getNurl() {
		return nurl;
	}

	public void setNurl(String nurl) {
		this.nurl = nurl;
	}

	public String getPurl() {
		return purl;
	}

	public void setPurl(String purl) {
		this.purl = purl;
	}
	
	public String getOurl() {
		return ourl;
	}

	public void setOurl(String ourl) {
		this.ourl = ourl;
	}
	
	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}
	
}
